import { Key, useEffect, useState } from "react";
import { IDelListProps } from "./type";
import { message, Modal } from "antd";
const { confirm } = Modal;
export default function useDeleteList(props: IDelListProps) {
  const [ids, setIds] = useState([] as Key[]);
  useEffect(() => {
    ids.length > 0 && delData();
  }, [ids]);
  const delData = () => {
    confirm({
      title: props.title || "确认删除改数据吗？",
      async onOk() {
        const res = await props.API(ids);
        props.success();
        if (res.data.success) {
          message.success("删除成功");
        } else {
          message.success(`删除失败,${res.data.errMessage}`);
        }
      },
    });
  };
  return {
    setIds,
  };
}
